import echarts from 'echarts';
// 引入柱状图
import 'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import storageApi from '../../core/storage/storage';

/*eslint-disable */
@Inject('$log', '$scope', '$rootScope', '$state', '$http', 'homeStatsService', 'ngDialog')
class consGroupProfileHomeController {
  constructor() {
    this.data = {};
    this.unitName = $state.params.name;
    this.orgId = $state.params.orgId;
    this.userName = $rootScope.userName ||  storageApi.get('userName');
  }

  logout() {
    this
      .$http
      .get('/api/v1/logout')
      .then((res) => {
        if (res.success) {
          this.$state.go('login');
          this.$rootScope.isLogined = false;
          // this.$interval.cancel(this.$rootScope.msgInterval);
        }
      });
  }

  changePwd() {
    this.ngDialog.open({
      template: 'consHomePwdDialog',
      className: 'ngdialog-theme-default pa-confirm-theme pa-confirm-self systemManage-add-dialog',
      controllerAs: '$consHomePwdDialog',
      controller($rootScope, $http, $scope, $log, $state, loginService, ngDialogService) {
        'ngInject';

        this.userInfo = {
          loginName: $rootScope.userName || storageApi.get('userName'),
        };

        this.submit = (param) => {
          // 修改表单是否提交过状态
          param.$submitted = true;
          // 表单校验
          if (param.$invalid) {
            return false;
          } else if (param.confirmPassWord.$viewValue !== param.newPassWord.$viewValue) {
            ngDialogService.alertError('确认密码和新密码不一致');
            return false;
          } else {
            loginService.update(this.userInfo)
              .then((res) => {
                if (res.success) {
                  ngDialogService.alertSuccess(res.message);
                  $scope.closeThisDialog();
                  $state.go('login');
                } else {
                  ngDialogService.alertError(res.message);
                }
              });
          }
        };
      },
    });
  }

}

export default consGroupProfileHomeController;
